﻿Imports System.IO
Imports CrystalDecisions.Shared

Public Class Principal
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Menu_MenuItemClick(sender As Object, e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu.MenuItemClick
        Select Case e.Item.Target
            Case "email"
                Dim rpt As New EmailRPT
                Try
                    rpt.SetDatabaseLogon("estagiario_elixo", "elixotoledo")
                    ' Rotina para mostrar contrato em pdf na tela usando memoria
                    Dim strExportFile As String = "emails.pdf" 'pode ser qq nome
                    Dim s As System.IO.MemoryStream = rpt.ExportToStream(ExportFormatType.PortableDocFormat)
                    With HttpContext.Current.Response
                        .ClearContent()
                        .ClearHeaders()
                        .ContentType = "application/octet-stream"
                        .AddHeader("Content-Disposition", "attachment; filename=" & strExportFile)
                        '.AddHeader("Content-Disposition", "inline; filename=" & strExportFile)
                        .BinaryWrite(s.ToArray)
                        '.End()
                    End With
                    s.Dispose()
                    rpt.Close()
                    rpt.Dispose()
                    rpt = Nothing
                Catch ex As Exception
                    'erro
                End Try
            Case "eletronicos"
                Dim rpt As New EletronicosColetadosRPT

                Try

                    rpt.SetDatabaseLogon("estagiario_elixo", "elixotoledo")
                    Dim strExportFile As String = "eletronicos.pdf" 'pode ser qq nome
                    Dim s As System.IO.MemoryStream = rpt.ExportToStream(ExportFormatType.PortableDocFormat)
                    With HttpContext.Current.Response
                        .ClearContent()
                        .ClearHeaders()
                        .ContentType = "application/octet-stream"
                        .AddHeader("Content-Disposition", "attachment; filename=" & strExportFile)
                        '.AddHeader("Content-Disposition", "inline; filename=" & strExportFile)
                        .BinaryWrite(s.ToArray)
                        '.End()
                    End With
                    s.Dispose()
                    rpt.Close()
                    rpt.Dispose()
                    rpt = Nothing
                Catch ex As Exception
                    'erro
                End Try
        End Select
    End Sub
End Class